package com.zhongke.cotrun.controller;

import com.zhongke.cotrun.common.util.APIResponse;
import com.zhongke.cotrun.model.pojo.UserIntegralHistory;
import com.zhongke.cotrun.model.resultpackage.CodeMsg;
import com.zhongke.cotrun.service.UserIntegralHistoryService;
import com.zhongke.cotrun.service.impl.UserIntegralHistoryServiceImpl;
import com.zhongke.cotrun.shiro.sys.shiro.ShiroUtils;
import com.zhongke.cotrun.shiro.web.entity.WebUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

@Validated
@RestController
@RequestMapping("/UserIntegralHistory")
public class UserIntegralHistoryController {
    @Autowired
    UserIntegralHistoryService userIntegralHistoryService;

    /**
     * 查看自己的历史记录
     *带分页
     * @param
     * @return
     */
    @PostMapping ("/selectUserIntegralHistorForMe")
    public APIResponse selectUserIntegralHistorForMe(UserIntegralHistory userIntegralHistory, Integer pageNumber, Integer pageSize) {
        WebUserEntity w = ShiroUtils.getWebUser();
        if (w == null) {
            return APIResponse.returnFail(CodeMsg.MUST_LOGIN_ERROP);
        }

        userIntegralHistory.setUserId(w.getUserId().intValue());
        return APIResponse.returnSuccess(userIntegralHistoryService.seleHistoryByCndition(userIntegralHistory, pageNumber, pageSize));

    }


    /**
     * 根据条件查看自己的历史记录
     *不带分页
     * @param userIntegralHistory
     * @return userId
     * rankOneOf
     * rankTwoOf
     * <p>
     * time
     */
    @PostMapping("/selectUserHistoryofMyBycondition")
    public APIResponse selectUserHistoryofMyBycondition(UserIntegralHistory userIntegralHistory) {
        WebUserEntity w = ShiroUtils.getWebUser();
        if (w == null) {
            return APIResponse.returnFail(CodeMsg.MUST_LOGIN_ERROP);
        }

        userIntegralHistory.setUserId(w.getUserId().intValue());

        return APIResponse.returnSuccess(userIntegralHistoryService.selectUserIntegralHistoryOfmy(userIntegralHistory));


    }

    /**
     * 查看自己的三个月的积分历史
     *
     * @param userId
     * @return
     */
    @GetMapping("/selectUserIntegralForThreeMounth")
    public APIResponse selectUserIntegralForThreeMounth(@NotNull(message = "用户id不能为空") Integer userId) {


        List l = userIntegralHistoryService.selctUserIntegralHistoryForThreeMounth(userId);

        if (l.size() == 0) {
            return APIResponse.returnSuccess();
        }
        return APIResponse.returnSuccess(l);
    }



}
